# from modelscope import snapshot_download
# model_dir = snapshot_download("Qwen/Qwen-1_8B-Chat-Int4")   # 一键下载模型

from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("D:\\ideaSpace\\MyPython\\models\\qwen\\Qwen-1_8B-Chat-Int4",  trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    "D:\\ideaSpace\\MyPython\\models\\qwen\\Qwen-1_8B-Chat-Int4",
    device_map="cpu",          # 强制 CPU
    trust_remote_code=True
).eval()

response, _ = model.chat(tokenizer, "你好", history=None)
print(response)